package cn.tedu.luban.worker.main.repository.impl;

import cn.tedu.luban.worker.main.converter.WorkerAreaConverter;
import cn.tedu.luban.worker.main.dao.WorkerAreaDAO;
import cn.tedu.luban.worker.main.repository.WorkerAreaRepository;
import cn.tedu.luban.worker.protocol.bo.WorkerAreaBO;
import cn.tedu.luban.worker.protocol.dos.WorkerAreaDO;
import cn.tedu.luban.worker.protocol.param.WorkerRegistAreaParam;
import cn.tedu.luban.worker.protocol.param.WorkerRegistParam;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class WorkerAreaRepositoryImpl implements WorkerAreaRepository {
    @Autowired(required = false)
    private WorkerAreaDAO workerAreaDAO;
    @Autowired
    private WorkerAreaConverter workerAreaConverter;
    @Override public void delete(Long userId) {
        workerAreaDAO.deleteByUserId(userId);
    }

    @Override public void saveWorkerAreas(WorkerRegistParam param) {
        List<WorkerRegistAreaParam> params = param.getWorkerRegistAreaParams();
        Long userId=param.getUserId();
        List<WorkerAreaDO> workerAreaDOS= workerAreaConverter.params2dos(params,userId);
        workerAreaDAO.batchInsert(workerAreaDOS);
    }

    @Override public List<WorkerAreaBO> getFrontAreas(Long userId) {
        List<WorkerAreaDO> workerAreaDOS=workerAreaDAO.selectByUserId(userId);
        return workerAreaConverter.dos2bos(workerAreaDOS);
    }

    @Override public List<WorkerAreaBO> getWorkerAreas(Long userId) {
        List<WorkerAreaDO> workerAreaDOS=workerAreaDAO.selectByUserId(userId);
        return workerAreaConverter.dos2bos(workerAreaDOS);
    }

}
